#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;
const int N = 110;
int f[N][N];
int n, k;
int main()
{
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
    {
        int w;
        cin >> w;
        for (int j = 0; i < k; j++)
            f[i][j] = max(f[i - 1][j], f[i - 1][(j + k - w % k) % k]);
    }
    cout << f[n][0] << endl;
    return 0;
}